package esya;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Query {
	
	String tableName="EVENTS";

	String[] inpSplit= new String[2];
	
	public String NameQuery(String s) throws ClassNotFoundException, SQLException{
		
		
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost/mysql?" + "user=root&password=";
	    Connection conn = DriverManager.getConnection(url);
		
		Statement stmt = null;
        ResultSet rs = null;
        
        String createString;
		createString= "SELECT * FROM "+ tableName +" WHERE event_name= \""+s+" \" ";
		
		stmt = conn.createStatement();
        stmt.executeQuery(createString);
        
        rs=stmt.executeQuery(createString);
        
        StringBuffer sb=new StringBuffer();
        String s1;
        
        String[] st={"event_name","date","time","venue","prizes"};
        
        while(rs.next()){
        	int i=0;
        	while(i<5){
        		s1=rs.getString(st[i]);
        		sb.append(" "+st[i]+": "+s1);
        		i++;
        	}
        }
     String result=sb.toString();
        //System.out.println("values inserted");
        	
        stmt.close();
        conn.close();
        
     //System.out.println(result);
	return result;
	}
	
	public String TimeQuery(int tim) throws SQLException, ClassNotFoundException{
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost/mysql?" + "user=root&password=";
	    Connection conn = DriverManager.getConnection(url);
		
		Statement stmt = null;
        ResultSet rs = null;
        
        String createString;
		createString= "SELECT * FROM "+ tableName +" WHERE time=\""+tim+" \" ";
		
		stmt = conn.createStatement();
        stmt.executeQuery(createString);
        
        rs=stmt.executeQuery(createString);
        
        StringBuffer sb1=new StringBuffer();
        String s2;
        
        String[] st={"event_name","date","time","venue","prizes"};
        //9873295225
        while(rs.next()){
        	int i=0;
        	while(i<5){
        		s2=rs.getString(st[i]);
        		sb1.append(" "+st[i]+": "+s2);
        		i++;
        	}
        }
     String result=sb1.toString();
        //System.out.println("values inserted");
        	
        stmt.close();
        conn.close();
	}
	

}
